#!/usr/bin/env python3 
# -*- coding: utf-8 -*- 
# @Author : Leo
# @File : pipelines.py 

from .mysqltool import Sqltool
from TianjinGovScrapy.items import TianjingovItem


class TianjingovPipline(object):

    def process_item(self, item, spider):
        Sqltool.createDBTable()
        if isinstance(item, TianjingovItem):
            news_id = item['news_id']
            news_title = item['news_title']
            news_date = item['news_date']
            news_url = item['news_url']
            news_content = item['news_content']
            area_id = item['area_id']
            Sqltool.insert2db(news_id=news_id,
                              news_title=news_title,
                              news_date=news_date,
                              news_url=news_url,
                              news_content=news_content,
                              area_id=area_id)
        else:
            pass
